package org.dfl.plugin.dialogs;

import java.awt.Frame;

import javax.swing.JFrame;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;

/**
 * dialog is a bridge for AWT frames
 * @author Piotr Wlodarczyk
 *
 */
public class AWTDialog extends BaseDialog {
	private JFrame awtPanel;
	
	public AWTDialog(JFrame awtPanel) {
		super();
		this.awtPanel = awtPanel;
	}

	@Override
	protected Shell getNewShell() {
		Shell shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
		shell.setSize((int)awtPanel.getBounds().getWidth()+50,(int)awtPanel.getBounds().getHeight()+50);
		shell.setText(awtPanel.getTitle());
		
		return shell;
	}

	@Override
	protected void init(Shell dialogShell) {
		Composite SWT_AWT_container = new Composite(dialogShell, SWT.EMBEDDED);
		SWT_AWT_container.setBounds(0,0,(int)awtPanel.getBounds().getWidth(),(int)awtPanel.getBounds().getHeight());

		Frame awtFrame = SWT_AWT.new_Frame(SWT_AWT_container);
		awtFrame.setResizable(true);
		awtFrame.add(awtPanel.getContentPane());
	}

}
